package com.ruoyi.test.dao;

import com.ruoyi.test.domain.Message;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MessageDao {
    //在mapper.xml中实现
    List<Message> selectAll(@Param("senderId") String senderId, @Param("receiverId") String receiverId);

    //在mapper.xml中实现
    void add(Message message);


    @Insert("INSERT INTO chat_message (sender_id, channel_id, content, receiver_id, timestamp)\n" +
            "VALUES (#{senderId}, (SELECT id FROM chat_channel WHERE name = #{toChannelName}), #{content} , #{receiverId}, #{timestamp} );")
    void addToChatMessage(Message msg);

    @Insert("INSERT INTO chat_channel_message (channel_id, message_id, is_deleted)\n" +
            "VALUES ((SELECT id FROM chat_channel WHERE name = #{toChannelName}), LAST_INSERT_ID(), 0);")
    void addToChatChannelMessage(Message msg);


    List<Message> selectAllForChannel(String toChannelName);
}
